from fastapi import APIRouter,Body, status
from fastapi.responses import JSONResponse
from blog import settings
from blog.utils import gen_token, verify_token


router = APIRouter(prefix="/auth", tags=['auth'])


@router.post("/login/")
async def login(username:str=Body(...), password:str=Body(...)):
    if username == settings.ADMIN_USERNAME and password ==  settings.ADMIN_PASSWORD:
        token = gen_token(username, password)
        return JSONResponse({"token":"Bearer "+token})
    else:
        return JSONResponse(status_code=status.HTTP_400_BAD_REQUEST)